package api

import (
	"longmen/server/config/global"
	"longmen/server/pkg/common/api_models"
	"longmen/server/pkg/common/helper/util"

	"github.com/labstack/echo/v4"
)

// @Summary Transit
// @Description Transit
// @Accept  json
// @Produce  json
// @Tags Config
// @Router /transit [POST]
func (base *Controller) Transit(c echo.Context) error {
	r := &api_models.TransitReq{}
	util.Json2Struct(c.Get("body").(string), r)
	if r.Gen == "" {
		return util.BuildFail(c, 1, "无效的地址", nil)
	}
	rkey := "transit-link:" + r.Gen
	ret, _ := global.GetRds().Get(rkey).Result()
	global.GetRds().Del(rkey)
	if ret == "" {
		return util.BuildFail(c, 1, "无效的地址", nil)
	}
	// des, err := base64.StdEncoding.DecodeString(ret)
	// if err != nil {
	// 	return util.BuildFail(c, 1, "无效的地址", err)
	// }
	base.Service.TransitStat()
	return util.BuildSuccessRaw(c, ret, ret)
}

// @Summary TransitOpen
// @Description Transit
// @Accept  json
// @Produce  json
// @Tags Config
// @Router /transit_open [POST]
func (base *Controller) TransitOpen(c echo.Context) error {

	base.Service.TransiOpenStat()
	return util.BuildSuccessRaw(c, nil, "")
}
